package com.fr.report.script.core;

import com.fr.base.core.BaseCoreUtils;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLReadable;
import com.fr.base.xml.XMLWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.report.io.xml.ReportXMLUtils;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

public class FArray
  implements Serializable, Cloneable, XMLWriter, XMLReadable
{
  private List list;
  private static final String SEPARATOR = ",";
  public static final String XML_TAG = "FARRAY";
  public static final String XML_VALUE = "FARRAYVALUE";

  public FArray()
  {
    this.list = new ArrayList();
  }

  public FArray(Object[] paramArrayOfObject)
  {
    this(Arrays.asList(paramArrayOfObject));
  }

  public FArray(FArray paramFArray)
  {
    this(paramFArray.list);
  }

  public FArray(Collection paramCollection)
  {
    this.list = new ArrayList();
    this.list.addAll(paramCollection);
  }

  public Object[] asObjects()
  {
    return this.list.toArray();
  }

  public Object elementAt(int paramInt)
  {
    return this.list.get(paramInt);
  }

  public int length()
  {
    return this.list.size();
  }

  public Iterator iterator()
  {
    return this.list.iterator();
  }

  public FArray add(Object paramObject)
  {
    if (paramObject instanceof FArray)
      this.list.addAll(((FArray)paramObject).list);
    else
      this.list.add(paramObject);
    return this;
  }

  public List toList()
  {
    return Collections.unmodifiableList(this.list);
  }

  public String toString()
  {
    return BaseCoreUtils.join(this.list, ",");
  }

  public boolean equals(Object paramObject)
  {
    if (!(paramObject instanceof FArray))
      return false;
    FArray localFArray = (FArray)paramObject;
    if (length() != localFArray.length())
      return false;
    for (int i = 0; i < length(); ++i)
      if (!(elementAt(i).equals(localFArray.elementAt(i))))
        return false;
    return true;
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("FARRAY");
    int i = 0;
    int j = length();
    while (i < j)
    {
      paramXMLPrintWriter.startTAG("FARRAYVALUE");
      ReportXMLUtils.writeObject(paramXMLPrintWriter, elementAt(i));
      paramXMLPrintWriter.end();
      ++i;
    }
    paramXMLPrintWriter.end();
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    if (paramXMLableReader.isChildNode())
    {
      String str = paramXMLableReader.getTagName();
      if ("FARRAYVALUE".equals(str))
        paramXMLableReader.readXMLObject(new XMLReadable(this)
        {
          private final FArray this$0;

          public void readXML()
          {
            if ((paramXMLableReader.isChildNode()) && ("O".equals(paramXMLableReader.getTagName())))
            {
              Object localObject = ReportXMLUtils.readObject(paramXMLableReader);
              this.this$0.add(localObject);
            }
          }
        });
    }
  }
}